const conn = require("../data");

// 跳转导航页面
module.exports.index = (req, res) => {
  res.render("index");
};
module.exports.about = (req, res) => {
  res.render("./about/about");
};
module.exports.cnt = (req, res) => {
  res.render("cnt");
};
module.exports.ctm = (req, res) => {
  res.render("ctm");
};
module.exports.gie = (req, res) => {
  res.render("gie");
};
module.exports.join = (req, res) => {
  res.render("join");
};
module.exports.news = (req, res) => {
  res.render("news");
};
module.exports.org = (req, res) => {
  res.render("org");
};

// 男装加盟二级页面
// 加盟优势
module.exports.advan = (req, res) => {
  res.render("join/advan");
};
// 加盟条件
module.exports.trem = (req, res) => {
  res.render("join/trem");
};
// 加盟流程
module.exports.flow = (req, res) => {
  res.render("join/flow");
};
// 加盟政策
module.exports.policy = (req, res) => {
  res.render("join/policy");
};

// // 男装定制产品二级页面
module.exports.ctm2 = (req, res) => {
  res.render("ctm/ctm2");
};
module.exports.ctm3 = (req, res) => {
  res.render("ctm/ctm2/ctm3");
};

// 渲染导航
module.exports.showNav = (req, res) => {
  if (req.query.nav_href.substring(0, 8) == "/article") {
    conn.query("select * from pc_nav; select * from pc_nav2;", (err, data) => {
      if (err) return console.log(err);
      res.json(data);
    });
  } else {
    conn.query(
      "select none from pc_nav2 where href=?",
      [req.query.nav_href],
      (err, none) => {
        if (none[0].none == 4) {
          conn.query(
            "select * from pc_nav; select * from pc_nav2;select name from pc_nav2 where href = ?; select * from pc_nav2 where nav_id=(select id from pc_nav2 where href=?)",
            [req.query.nav_href, req.query.nav_href],
            (err, data) => {
              if (err) return console.log(err);
              res.json(data);
            }
          );
        } else {
          conn.query(
            "select * from pc_nav; select * from pc_nav2;select name from pc_nav2 where href = ?; select * from pc_nav2 where nav_id=(select nav_id from pc_nav2 where href=?)",
            [req.query.nav_href, req.query.nav_href],
            (err, data) => {
              if (err) return console.log(err);
              res.json(data);
            }
          );
        }
      }
    );
  }
};

// 文章返回
module.exports.article = (req, res) => {
  conn.query(
    "select * from page_news where id=?",
    req.params.id,
    (err, data) => {
      if (err) return console.log(err);
      res.render("article", { data: data[0] });
    }
  );
};
